<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <img src="images/ldh.jpg" alt="">
    <button>更改src属性的值</button>
    <script src="js/public.js"></script>
    <script>
        var btn = document.querySelector('button')
        var img = $('img')
        btn.onclick = function() {

            if (img.getAttribute("src") == 'images/ldh.jpg') {
                img.src = 'images/zxy.jpg'

            } else {
                img.src = 'images/ldh.jpg'

            }
        }
    </script>
</body>

</html>